const router = require('koa-router')();
const areas = require('../models/areas.js');

router.prefix('/api/areas');


router.get('/', async (ctx, next) => {
  ctx.body = await areas.getAreas();
})

router.post('/', async (ctx, next) => {
  var name = ctx.request.body.area_name;
  console.log(name);
  ctx.body = await areas.addArea(name);
})

router.put('/:id', async (ctx, next) => {
  const id = ctx.params.id;
  const name = ctx.request.body.area_name;
  console.log(name);
  console.log(ctx.params.id);
  ctx.body = await areas.updateAreas(id,name);
})

router.delete('/:id', async (ctx, next) => {
  const id = ctx.params.id;
  console.log(id);
  ctx.body = await areas.delArea(id);
})



module.exports = router;
